/**
 * 获取数据类型
 * @param obj: any
 * @returns type: string
 */
const getType = obj => {
  const type = Object.prototype.toString
    .call(obj)
    .match(/^\[object (.*)\]$/)[1]
    .toLowerCase();
  if (type === 'string' && typeof obj === 'object') return 'object';
  if (obj === null) return 'null';
  if (obj === undefined) return 'undefined';
  return type;
};

// 二维坐标系一维线性表示
const MakeKey = (x = 0, y = 0) => y * 10000 + x;

/**
 * 迭代二维坐标系所有元素，执行回调函数
 * @param config: { width: number, height: number }
 * @param callback: (x: number, y: number) => boolean
 */
const IterateCells = ({ width, height }, callback) => {
  for (let y = 0; y < height; y++) {
    for (let x = 0; x < width; x++) {
      if (callback && !callback(x, y)) {
        return false;
      }
    }
  }
  return true;
};
